package C9_6_ReplaceConditionalWithPolymorphism;

/**
 * @author xugang1
 * @updated 2022/7/25
 * @description 以多态取代条件表达式
 */

public class Employee {
    /**
     * 重构前
     */

    private EmployeeType _type;

    public int payAmount() {
        switch (getType()) {
            case EmployeeType.ENGINEER:
                return _monthlySalary;
            case EmployeeType.SALESMAN:
                return _monthlySalary + _commission;
            case EmployeeType.MANAGER:
                return _monthlySalary + _bonus;
            default:
                throw new RuntimeException("Incorrect Employee")
        }
    }

    int getType(){
        return _type.getTypeCode();
    }


}